//
//  KCSignInOutCell.swift
//  MyKC
//
//  Created by yy on 2017/4/6.
//  Copyright © 2017年 com.yasuo. All rights reserved.
//

import UIKit

@objc protocol KCSignInOutCellDelegate: NSObjectProtocol {
    @objc optional func signBtnClick(tag: NSInteger)
}

class KCSignInOutCell: UITableViewCell {
    
    weak var delegate: KCSignInOutCellDelegate?
    
    var signArray: [KCWorkTaiSignInfoModel]? {
        //外界已经完成了的赋值
        didSet {
            if signArray?.count == 0 {
                viewSignInH.constant = 0
                viewSignOutH.constant = 0
                
                view_signIn.isHidden = true
                view_signOut.isHidden = true
                
                lbe_sign.isHidden = true
                lbe_signOut.isHidden = true
                
                brn_signIn.isHidden = false
                btn_signOut.isHidden = false
            }
            
            if signArray?.count == 1 {
                let model = signArray!.first!
                viewSignInH.constant = 43
                viewSignOutH.constant = 0
                
                view_signIn.isHidden = false
                view_signOut.isHidden = true
                
                lbe_sign.isHidden = false
                lbe_signOut.isHidden = true
                
                brn_signIn.isHidden = true
                btn_signOut.isHidden = false
                
                lbe_signInTime.text = model.AttendanceTime
                //考勤异常
                if model.correctArea == "0" {
                    lbe_signStatus.text = "考勤异常"
                    imv_signInYiChang.image = UIImage(named: "异常")
                }else {
                    lbe_signStatus.text = "考勤正常"
                    imv_signInYiChang.image = UIImage(named: "考勤正常")
                }
            }
                
            //已经上下班签到了---------
            else if signArray?.count == 2 {
                let signInModel = signArray!.first!
                let signOutModel = signArray!.last!
                
                view_signIn.isHidden = false
                view_signOut.isHidden = false
                
                lbe_sign.isHidden = false
                lbe_signOut.isHidden = false
                
                brn_signIn.isHidden = true
                btn_signOut.isHidden = true
                
                viewSignInH.constant = 43
                viewSignOutH.constant = 43
                
                lbe_signInTime.text = signInModel.AttendanceTime
                lbe_signOutStatus.text = signOutModel.AttendanceTime
                
                //考勤异常
                if signInModel.correctArea == "0" {
                    lbe_signStatus.text = "考勤异常"
                    imv_signInYiChang.image = UIImage(named: "异常")
                }else {
                    lbe_signStatus.text = "考勤正常"
                    imv_signInYiChang.image = UIImage(named: "考勤正常")
                }
                
                if signOutModel.correctArea == "0" {
                    lbe_signOutStatus.text = "考勤异常"
                    imv_signOutYiChang.image = UIImage(named: "异常")
                }else {
                    lbe_signOutStatus.text = "考勤正常"
                    imv_signOutYiChang.image = UIImage(named: "考勤正常")
                }

            }
        }
    }
    
    @IBOutlet weak var viewSignInH: NSLayoutConstraint!
    @IBOutlet weak var viewSignOutH: NSLayoutConstraint!
    @IBOutlet weak var brn_signIn: UIButton!
    @IBOutlet weak var lbe_sign: UILabel!
    @IBOutlet weak var view_signIn: UIView!
    @IBOutlet weak var lbe_signStatus: UILabel!
    @IBOutlet weak var lbe_signInTime: UILabel!
    @IBOutlet weak var imv_signInYiChang: UIImageView!
    
    @IBOutlet weak var btn_signOut: UIButton!
    @IBOutlet weak var lbe_signOut: UILabel!
    @IBOutlet weak var view_signOut: UIView!
    @IBOutlet weak var lbe_signOutStatus: UILabel!
    @IBOutlet weak var lbe_signOutTime: UILabel!
    @IBOutlet weak var imv_signOutYiChang: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        btn_signOut.layer.cornerRadius = 5
        brn_signIn.layer.cornerRadius = 5
        btn_signOut.clipsToBounds = true
        brn_signIn.clipsToBounds = true
    }


    @IBAction func signBtnClick(_ sender: UIButton) {
        //签到的是10   签退的是20
        delegate?.signBtnClick?(tag: sender.tag)
    }
}
